package com.codedef.diaryserver.service;

import com.codedef.diaryserver.domain.DiaryDao;
import com.codedef.diaryserver.repository.DiaryRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DiaryService {

    @Autowired
    DiaryRepository diaryRepository;

    public List<DiaryDao> getDiaryList(Integer userId) {
        return diaryRepository.findAllByUserId(userId);
    }

    public boolean addOrUpdate(DiaryDao diary) {
        return diaryRepository.save(diary) != null ? true : false;
    }

    public void deleteDiary(Integer diaryId) {
        diaryRepository.deleteById(diaryId);
    }

    public DiaryDao getDiaryById(Integer integer) {
        return diaryRepository.findById(integer).get();
    }

}
